Back to course home
0% completed
Vote For New Content
Microsoft Hard Problems
Regular Expression Matching (hard)
Solution: Regular Expression Matching
First Missing Positive (hard)
Solution: First Missing Positive
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Sliding Window Maximum (hard)
Solution: Sliding Window Maximum
Count Unique Characters of All Substrings of a Given String (hard)
Solution: Count Unique Characters of All Substrings of a Given String
Word Ladder (hard)
Solution: Word Ladder
Word Ladder II (hard)
Solution: Word Ladder II
Number of Flowers in Full Bloom (hard)
Solution: Number of Flowers in Full Bloom
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Reverse Words in a String II (medium)
Problem Statement
Given a character array s, return the updated array after reversing the order of words in the array.
A word is defined as a sequence of non-space characters, and the words are separated by one space character. The input array does not contain any leading or trailing spaces, and the words are always separated by a single space.
Note: Your code must solve the problem without using any extra space.
Examples
-
Example 1:
- Input:
["h","e","l","l","o"," ","w","o","r","l","d"] - Expected Output:
["w","o","r","l","d"," ","h","e","l","l","o"] - Justification: The original string is "hello world". Reversing the words gives "world hello".
- Input:
-
Example 2:
- Input:
["m","o","r","n","i","n","g"," ","s","k","y"," ","i","s"," ","b","r","i","g","h","t"] - Expected Output:
["b","r","i","g","h","t"," ","i","s"," ","s","k","y"," ","m","o","r","n","i","n","g"] - Justification: The original string is "morning sky is bright". Reversing the words gives "bright is sky morning".
- Input:
-
Example 3:
- Input:
["a","l","o","n","e"] - Expected Output:
["a","l","o","n","e"] - Justification: There's only one word "alone", so the reverse is the same as the original.
- Input:
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Find Original Array From Doubled Array
Solution: Reverse Words in a String II
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself